+function($){
  var deletedialog;
  //修改品牌
  $('body').on('click', '.updateBrand', function() {
    var bid = $(this).parent().data('bid');
    var bname = $(this).parent().prevAll('.J_bname').text();
     var str = '<ul>'+
      '<li style="list-style:none;"><laber class="list-laber">品牌:</laber><input type="text" name="bname" class="list-input" id="bname" value="'+bname+'"></li>'+
      '<div class="dialog-button" style="margin-top:12px;"><button style="margin-left:86px;" class="btn btn-sm btn-primary" value="'+bid+'" id="updatebrand">修　改</button></div>'+
      '</ul>';
      var d = dialog({
        title:'修改品牌',
        content: str,
        width:'300px',
        skin:'  dialog-box',
        lock:true,
        padding:'10px'
      }).showModal();
  });
  $('body').on('click', '#updatebrand', function() {
    $.post('/brand/updateBrand', {bname: $('#bname').val(),bid:$(this).val()}, function(data) {
      if(data!='false'){
        location.reload(true);
      }else{
        alert('修改失败');
      }
    });
  });
  //删除品牌
  $('body').on('click', '.deleteBrand', function() {
    var content = '<span style="color:#d00">确定要删除这一条品牌记录吗？</span></br>'+
                  '<span style="color:#d00;font-weight:700">注意！与此相关的数据会一并删除</span>'+
                  '<div style="margin-top:12px;" class="dialog-button"><button style="margin-left:75px;" class="btn btn-sm btn-danger" id="brandDelete" value="'+$(this).parent().data('bid')+'">确定</button><button style="margin-left:30px;" class="btn btn-sm btn-grey" id="closeDelete">取消</button></div>';
    deletedialog = dialog({
      title:'温馨提示',
      content: content,
      width:'300px',
      skin:'  dialog-box',
      lock:true,
      padding:'10px'
    }).showModal();
  });
  $('body').on('click', '#closeDelete', function() {
     deletedialog.close();
   });
  $('body').on('click', '#brandDelete', function() {
      $.post("/brand/deleteBrand",{
        bid:$(this).val()
      },function(data){
        location.reload(true);
      });
   });
   //添加品牌
   $('body').on('click', '#addbrand', function() {
     var str = '<ul>'+
      '<li style="list-style:none;"><laber class="list-laber">品牌:</laber><input type="text" name="bname" class="list-input" id="bname"></li>'+
      '<div class="dialog-button" style="margin-top:12px;"><button style="margin-left:86px;" class="btn btn-sm btn-primary" id="addBrand">添　加</button></div>'+
      '</ul>';
      var d = dialog({
        title:'添加品牌',
        content: str,
        width:'300px',
        skin:'  dialog-box',
        lock:true,
        padding:'10px'
      }).showModal();
   });
   $('body').on('click', '#addBrand', function() {
     $.post('/brand/addBrand', {bname: $('#bname').val()}, function(data) {
       if(data!='false'){
         alert('添加成功');
         location.reload(true);
       }
     });
   });
  $('body').on('click', '.zdyj', function(event) {
    var bname = $(this).parent().prevAll('.J_bname').text();
    var content = '<ul>'+
        '<input type="hidden" name="bid" id="bid" value='+$(this).data('bid')+'>'+
        '<li>品&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;牌：<span class="J_emname">'+bname+'</span></li>'+
        '<li>选择月份：<div style="display:inline" class="YMD" data-ys="2017" data-ye="1880" id="embirth"> <select class="YYYY" name="birth-YYYY"> <option value="">请选择 年</option> </select> <select class="MM" name="birth-MM"> <option value="">选择 月</option> </select> </div>'+
        '<div class="dialog-button"><button style="margin-right:20px;" class="btn btn-sm btn-primary" data-bid="'+$(this).data('bid')+'" id="alloutput">全部导出</button><button class="btn btn-sm btn-primary" data-bid="'+$(this).data('bid')+'" id="output">按月份导出</button></div>'+
        '</ul>';
    var $this = $(this);
    var d = dialog({
      title:'温馨提示',
      content: content,
      width:'400px',
      skin:'  dialog-box',
      lock:true,
      padding:'10px'
    }).showModal($('.YMD').ymd());
  });
  $('body').on('click', '#alloutput', function(event) {
    window.location.href='/brand/tecountexcel?bid='+$(this).data('bid');
  });
  $('body').on('click', '#output', function() {
    var flag = true;
    $('.YYYY,.MM').each(function(index, el) {
        if($(this).val()==''){
          $(this).css('border', '3px solid #f77');
					flag = false;
          alert('请将信息补充完整');
					return false;
        }
        $(this).attr('style', ' ');
    });
		if(flag == false){
			return false;
		}
    window.location.href='/brand/tecountexcel?bid='+$(this).data('bid')+'&month='+$('select[name="birth-MM"]').val()+'&year='+$('select[name="birth-YYYY"]').val();
  });

}(jQuery);
